<template>
  <view>
    <view v-if="isShowMsg === 'Y'" class="record-wrapper">
      <view class="bottom">
        <tui-grid>
          <tui-grid-item v-for="(item, index) in girdList" :key="index" :border="false" :bottom-line="false"
                         :cell="3" :class="index < 4 ? 'uni-grid-item-botom' : ''" :index="index"
                         backgroundColor="rgba(255,255,255,0.1)"
                         @click="handerClick(item)">
            <view class="grid-item-box">
              <image :src="item.url" class="img-item"/>
              <text class="text">{{ item.name }}</text>
            </view>
          </tui-grid-item>
        </tui-grid>
      </view>
      <tui-tips ref="toast"></tui-tips>
    </view>
    <wannianliVue v-else/>
  </view>
</template>

<script>
import {commonStorage} from "@/utils/common.js";
import {getGridListApi, loginWechatApi, saveOrUpdate} from "@/apis/user.js";
import shareSdk from '@/utils/share.js'
import wannianliVue from '../wannianli/wannianli.vue';
import showPage from '@/utils/showPage'

export default {
  mixins: [shareSdk, showPage],
  components: {
    wannianliVue
  },
  data() {
    return {
      autoplay: true,
      interval: 3000,
      girdList: [],

      userInfo: {}
    };
  },
  mounted() {
  },
  async onShow() {
    let mobile = commonStorage.getStorageSync("mobile");
    if (!mobile) {
      const userInfo = commonStorage.getStorageSync("userInfo");
      if (userInfo) {
        mobile = JSON.parse(userInfo).mobile || '';

      }

    }
    if (mobile) {
      let {code, data} = await loginWechatApi({
        mobile: mobile
      });
      if (code == 1) {
        commonStorage.setStorage("token", data.token);
        commonStorage.setStorage("userInfo", JSON.stringify(data.userVO));
        const userVO = data.userVO
        if (!userVO.birthDate || !userVO.nickName || !userVO.birthPlace) {
          uni.showToast({
            title: '请先去我的页面完善个人信息',
            icon: 'none'
          })
        }
      }
    }
    this.getMenu()

  },

  created() {
  },

  onLoad(opt) {
    // this.currentStatus = commonStorage.getStorageSync("currentStatus");
    // this.getGridList();
    // this.initUserInfo();
  },
  methods: {

    getMenu() {

      saveOrUpdate().then(res => {
        const list = JSON.parse(res.data)


        list.forEach(it => {
          it.url = 'https://ai-sbbs.xyz/api/sys/img/show?name=' + it.imgUrl
        })
        this.girdList = [...list]
        console.log(this.girdList, 'girdList');

      })
    },
    change(e) {
      console.log("当前轮播信息：", e);
    },

    async getGridList() {
      let {code, data} = await getGridListApi();
      if (code == 1) {
        this.girdList = data;
      }
    },
    // 获取用户信息
    initUserInfo() {
      let userInfo =
          commonStorage.getStorageSync("userInfo") &&
          JSON.parse(commonStorage.getStorageSync("userInfo"));
      if (userInfo) {
        this.userInfo = userInfo;
      }
    },

    handerClick(item) {
      // if (this.$route.query.token) {
      //   let params = {
      //     title: ""
      //   };
      //   return this.$refs.toast && this.$refs.toast.show(params);
      // } else {
      //   let params = {
      //     title: "出生日期不能为空"
      //   };
      //   return this.$refs.toast && this.$refs.toast.show(params);
      // }
      // if (!this.userInfo.userId) {
      //   return uni.navigateTo({ url: "/pages/login/login" });
      // }
      console.log(item);
      if (item.navigateTo) {
        item.id = item.navigateTo
      }
      if (item.id == 6) {
        uni.navigateTo({
          // url: "/pqgeInfo/wannianli/wannianli"
          url: "/pages/wannianli/wannianli"
        });
      } else if (item.id == 1 || item.id == 5) {
        uni.navigateTo({
          url: "/pages/record/qiuqian?flag=" + item.id
        });
      } else if (item.id == 7) {
        uni.navigateTo({
          url: "/pages/record/xiaoliuren?flag=" + item.id
        });
      } else if (item.id == 8) {
        uni.navigateTo({
          url: "/pages/record/zhougongjiemeng?flag=" + item.id
        });
      } else if (item.id == 9) {
        uni.navigateTo({
          url: "/pqgeInfo/zaixianqiming/zaixianqiming?flag=" + item.id
        });
      } else if (item.id == 10) {
        uni.navigateTo({
          url: "/pqgeInfo/xingmingdafen/xingmingdafen?flag=" + item.id
        });
      } else if (item.id == 12) {
        uni.navigateTo({
          url: "/pqgeInfo/gongsimingdafen/gongsimingdafen?flag=" + item.id
        });
      } else if (item.id == 13) {
        uni.navigateTo({
          url: "/pqgeInfo/xingzuo/xingzuo?flag=" + item.id
        });
      } else if (item.id == 14) {
        uni.navigateTo({
          url: "/pqgeInfo/shengxiao/shengxiao?flag=" + item.id
        });
      } else if (item.id == 16) {
        uni.navigateTo({
          url: "/pqgeInfo/yaogua/yaogua?flag=" + item.id
        });
      } else if (item.id == 2 || item.id == 3) {
        uni.navigateTo({
          url: "/pages/record/bazihe?flag=" + item.id
        });
      } else if (item.id == 15) {
        // 生成头像
        uni.navigateTo({
          url: "/pqgeInfo/generateAvatar/index"
        })
      } else if(item.id == 19){
        uni.navigateTo({
          url:'/pqgeInfo/baziActuarial/baziActuarial'
        })
      } else if(item.id == 20){
        uni.navigateTo({
          url:'/pqgeInfo/fortune/fortune'
        })
      }
    }
  }
};
</script>

<style lang="scss">
.record-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  padding: 12px;
  // background: #f6f6f6;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  background-image: url(https://ai-sbbs.xyz/api/profile/upload/2024/07/01/216ecf4ef90549a1b0d6b8cd648786f9.png);
  background-size: cover;
  background-repeat: no-repeat;
  height: 100vh;

  .bottom {
    border-radius: 2px;
    position: relative;

    .grid-item-box {
      display: flex;
      flex-direction: column;
      align-items: center;
      font-size: 14px;
      color: #666666;

      .img-item {
        width: 56px;
        height: 56px;
      }

      .text {
        font-size: 12px;
      }
    }
  }
}
</style>
